#include "mcsinglevalue.h"

#include <cmath>

namespace MCCommon
{

static const double kTolerance = 10e-14;

MCSingleValue::MCSingleValue()
{
    fValueType = kVT_Integer;
    fNumValue.dval = 0;
}

MCSingleValue::MCSingleValue
(
    bool val
)
{
    fValueType = kVT_Bool;
    fNumValue.bval = val;    
}

MCSingleValue::MCSingleValue
( 
    int value 
)
{
    fValueType = kVT_Integer;
    fNumValue.ival = value;
}

MCSingleValue::MCSingleValue
( 
    double value 
)
{
    fValueType = kVT_Double;
    fNumValue.dval = value;
}

MCSingleValue::MCSingleValue
(
    const std::string& value
)
{
    fValueType = kVT_String;
    fStrValue = value;
}

MCSingleValue::~MCSingleValue(void)
{
}

IMCSettingValue::ValueType 
MCSingleValue::GetValueType() const
{
    return fValueType;
}

IMCSettingValue* 
MCSingleValue::Clone() const
{
    MCSingleValue* pValue = new MCSingleValue();
    pValue->fValueType = fValueType;
    pValue->fNumValue = fNumValue;
    
    return pValue;
}

bool 
MCSingleValue::GetBool() const 
{
    return fNumValue.bval;   
}

int 
MCSingleValue::GetInt() const
{
    return fNumValue.ival; 
} 

double 
MCSingleValue::GetDouble() const
{
    return fNumValue.dval;
}

std::string 
MCSingleValue::GetString() const 
{
    return fStrValue;
}

void 
MCSingleValue::SetBool
(   
    bool value
)
{
    fValueType = kVT_Bool;
    fNumValue.bval = value;
}
void MCSingleValue::SetInt
(
    int value
)
{
    fValueType = kVT_Integer;
    fNumValue.ival = value;
}

void 
MCSingleValue::SetDouble
(
    double value
)
{
    fValueType = kVT_Double;
    fNumValue.dval = value;
}

void 
MCSingleValue::SetString
(
    const std::string& value
)
{
    fValueType = kVT_String;
    fStrValue = value;
}

} // end of namespace MCCommon.